using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ICP_MS.Plugin.LA300;

public class FormResults : Form
{
	private ExperimentDatas experiment = null;

	private ExperimentDB db = null;

	private FormCurves formCurves = null;

	private FormNumerics formNumerics = null;

	private FormDistribution formDistrib = null;

	private IContainer components = null;

	private TabControl tabResults;

	private TabPage pageCurves;

	private TabPage pageNumerics;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;

	private DataGridViewTextBoxColumn dataGridViewTextBoxColumn5;

	private TabPage pageDistribution;

	public FormResults()
	{
		InitializeComponent();
	}

	public void SetParams(ExperimentDatas experiment, ExperimentDB db)
	{
		this.experiment = experiment;
		this.db = db;
	}

	private void experiment_isotopeChanged(object sender, EventArgs e)
	{
		if (formCurves != null)
		{
			formCurves.UpdateSelectedIsotopes(sender, e);
		}
		if (formNumerics != null)
		{
			formNumerics.UpdateSelectedIsotopes(sender, e);
		}
		if (formDistrib != null)
		{
			formDistrib.UpdateSelectedIsotopes(sender, e);
		}
	}

	private void experiment_istdChanged(object sender, EventArgs e)
	{
		if (formCurves != null)
		{
			formCurves.UpdateInternalStandards(sender, e);
		}
		if (formNumerics != null)
		{
			formNumerics.UpdateInternalStandards(sender, e);
		}
	}

	private void experiment_sampleChanged(object sender, EventArgs e)
	{
		if (formCurves != null)
		{
			formCurves.UpdateSamples(sender, e);
		}
		if (formNumerics != null)
		{
			formNumerics.UpdateSamples(sender, e);
		}
		if (formDistrib != null)
		{
			formDistrib.UpdateSelectedSamples(sender, e);
		}
	}

	private void FormResults_Load(object sender, EventArgs e)
	{
		base.WindowState = FormWindowState.Maximized;
		formCurves = new FormCurves();
		formCurves.SetParams(experiment, db);
		formCurves.FormBorderStyle = FormBorderStyle.None;
		formCurves.TopLevel = false;
		formCurves.Dock = DockStyle.Fill;
		formCurves.Parent = pageCurves;
		formCurves.Show();
		formNumerics = new FormNumerics();
		formNumerics.SetParams(experiment, db);
		formNumerics.FormBorderStyle = FormBorderStyle.None;
		formNumerics.TopLevel = false;
		formNumerics.Dock = DockStyle.Fill;
		formNumerics.Parent = pageNumerics;
		formNumerics.Show();
		formDistrib = new FormDistribution();
		formDistrib.SetParams(experiment, db);
		formDistrib.FormBorderStyle = FormBorderStyle.None;
		formDistrib.TopLevel = false;
		formDistrib.Dock = DockStyle.Fill;
		formDistrib.Parent = pageDistribution;
		formDistrib.Show();
		ApplyResource();
		experiment.isotopeChanged += experiment_isotopeChanged;
		experiment.sampleChanged += experiment_sampleChanged;
		experiment.istdChanged += experiment_istdChanged;
	}

	private void ApplyResource()
	{
		Text = Lang.Txt("FormResults.Title.Text");
		pageCurves.Text = Lang.Txt("FormResults.CaliCurve.Text");
		pageNumerics.Text = Lang.Txt("FormResults.Results.Text");
		pageDistribution.Text = Lang.Txt("FormScanLA.pageDistribution");
	}

	private void FormResults_FormClosing(object sender, FormClosingEventArgs e)
	{
		formCurves.Close();
		formCurves.Dispose();
		formNumerics.Close();
		formNumerics.Dispose();
		experiment.isotopeChanged -= experiment_isotopeChanged;
		experiment.sampleChanged -= experiment_sampleChanged;
		experiment.istdChanged -= experiment_istdChanged;
	}

	public void RefreshResults()
	{
		formNumerics.RefreshResults();
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.tabResults = new System.Windows.Forms.TabControl();
		this.pageCurves = new System.Windows.Forms.TabPage();
		this.pageNumerics = new System.Windows.Forms.TabPage();
		this.pageDistribution = new System.Windows.Forms.TabPage();
		this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.tabResults.SuspendLayout();
		base.SuspendLayout();
		this.tabResults.Alignment = System.Windows.Forms.TabAlignment.Bottom;
		this.tabResults.Controls.Add(this.pageCurves);
		this.tabResults.Controls.Add(this.pageNumerics);
		this.tabResults.Controls.Add(this.pageDistribution);
		this.tabResults.Dock = System.Windows.Forms.DockStyle.Fill;
		this.tabResults.Location = new System.Drawing.Point(0, 0);
		this.tabResults.Name = "tabResults";
		this.tabResults.SelectedIndex = 0;
		this.tabResults.Size = new System.Drawing.Size(823, 488);
		this.tabResults.TabIndex = 4;
		this.pageCurves.Location = new System.Drawing.Point(4, 4);
		this.pageCurves.Name = "pageCurves";
		this.pageCurves.Padding = new System.Windows.Forms.Padding(3);
		this.pageCurves.Size = new System.Drawing.Size(815, 462);
		this.pageCurves.TabIndex = 0;
		this.pageCurves.Text = "校准曲线";
		this.pageCurves.UseVisualStyleBackColor = true;
		this.pageNumerics.Location = new System.Drawing.Point(4, 4);
		this.pageNumerics.Name = "pageNumerics";
		this.pageNumerics.Padding = new System.Windows.Forms.Padding(3);
		this.pageNumerics.Size = new System.Drawing.Size(815, 462);
		this.pageNumerics.TabIndex = 1;
		this.pageNumerics.Text = "样品结果";
		this.pageNumerics.UseVisualStyleBackColor = true;
		this.pageDistribution.Location = new System.Drawing.Point(4, 4);
		this.pageDistribution.Name = "pageDistribution";
		this.pageDistribution.Padding = new System.Windows.Forms.Padding(3);
		this.pageDistribution.Size = new System.Drawing.Size(815, 462);
		this.pageDistribution.TabIndex = 2;
		this.pageDistribution.Text = "二维分布";
		this.pageDistribution.UseVisualStyleBackColor = true;
		this.dataGridViewTextBoxColumn1.HeaderText = "标准名称";
		this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
		this.dataGridViewTextBoxColumn1.ReadOnly = true;
		this.dataGridViewTextBoxColumn1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
		this.dataGridViewTextBoxColumn1.Width = 59;
		this.dataGridViewTextBoxColumn2.HeaderText = "浓度";
		this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
		this.dataGridViewTextBoxColumn2.ReadOnly = true;
		this.dataGridViewTextBoxColumn2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
		this.dataGridViewTextBoxColumn2.Width = 35;
		this.dataGridViewTextBoxColumn3.HeaderText = "计算浓度";
		this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
		this.dataGridViewTextBoxColumn3.ReadOnly = true;
		this.dataGridViewTextBoxColumn3.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
		this.dataGridViewTextBoxColumn3.Width = 59;
		this.dataGridViewTextBoxColumn4.HeaderText = "偏差";
		this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
		this.dataGridViewTextBoxColumn4.ReadOnly = true;
		this.dataGridViewTextBoxColumn4.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
		this.dataGridViewTextBoxColumn4.Width = 35;
		this.dataGridViewTextBoxColumn5.HeaderText = "强度";
		this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
		this.dataGridViewTextBoxColumn5.ReadOnly = true;
		this.dataGridViewTextBoxColumn5.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
		this.dataGridViewTextBoxColumn5.Width = 35;
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(823, 488);
		base.Controls.Add(this.tabResults);
		base.Name = "FormResults";
		base.ShowIcon = false;
		this.Text = "FormResults";
		base.FormClosing += new System.Windows.Forms.FormClosingEventHandler(FormResults_FormClosing);
		base.Load += new System.EventHandler(FormResults_Load);
		this.tabResults.ResumeLayout(false);
		base.ResumeLayout(false);
	}
}
